<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<div class="modal-dialog ms-modal-dialog" style="width: 510px; margin-top: 150px;">
  <div class="modal-content">

    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
      <h4 class="modal-title">服务供方 - 修改供方级别</h4>
    </div>

    <form class="form-horizontal ms-form modal-search-form" role="form" method="POST" 
          action="${ctx.host}/suppliers/${supplier.id}/change-level" data-validate="true">
    
      <input type="hidden" name="_method" value="PATCH">

      <div class="modal-body">

        <c:if test="${supplier.first}">
        
          <c:if test="${empty subSuppliers}">
            <p class="text-center" style="font-size: 12px; color: #666;">该一级供方下无下属供方</p>
          </c:if>
          <c:if test="${not empty subSuppliers}">
            <p style="font-size: 12px; color: #df1010; margin-left: 25px;">请注意，该供方为一级供方，请先清理下属供方关系后再转换。下属公司如下：</p>
            <c:forEach var="subSupplier" items="${subSuppliers}" varStatus="status">
              <p style="margin-left: 30px;">${status.count}&nbsp;.&nbsp;${subSupplier.code} - ${subSupplier.shortName}</p>
            </c:forEach>
          </c:if>
          
          <br/>
          
          <c:if test="${empty users}">
            <p class="text-center" style="font-size: 12px; color: #666; margin-bottom: 25px;">该一级供方下无相关用户</p>
          </c:if>
          <c:if test="${not empty users}">
            <p style="font-size: 12px; color: #df1010; margin-bottom: 10px; margin-left: 25px;">该一级供方相关用户如下，如转换一二级供方会删除以下用户：</p>
            <p style="margin-left: 30px;">
              <c:forEach var="user" items="${users}" varStatus="status">
                ${status.count}&nbsp;.&nbsp;${user.loginName}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              </c:forEach>
            </p>   
            <p style="font-size: 12px; color: #df1010; margin-bottom: 20px; margin-left: 25px;">确定要删除以上用户吗？</p>
          </c:if>
        
          <div class="form-group  ms-form-group">
            <label class="control-label col-xs-3">挂靠管理公司：</label>
            <div class="col-xs-8 pull-left">
              <select class="select2 form-control" name="parents" data-validate="required" multiple="multiple">
                <option></option>
                <c:forEach items="${suppliers}" var="supplier">
                  <option value="${supplier.id}">${supplier.name}</option>
                </c:forEach>
              </select>
            </div>
          </div>
          
        </c:if>
        
        
        <c:if test="${not supplier.first}">
          
          <c:if test="${empty users}">
            <p class="text-center" style="font-size: 12px; color: #666; margin-bottom: 25px;">该二级供方下无相关用户</p>
          </c:if>
          
          <c:if test="${not empty users}">
            <p style="font-size: 12px; color: #df1010; margin-bottom: 10px; margin-left: 25px;">该二级供方相关用户如下，如转换一二级供方会删除以下用户：</p>
            <p style="margin-left: 30px;">
  	          <c:forEach var="user" items="${users}" varStatus="status">
                ${status.count}&nbsp;.&nbsp;${user.loginName}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  	          </c:forEach>   
            </p>
            <p style="font-size: 12px; color: #df1010; margin-bottom: 20px; margin-left: 25px;">确定要删除以上用户吗？</p>
          </c:if>
          
        </c:if>
         
      </div>

      <div class="modal-footer ms-modal-footer">
        <button type="submit" class="btn ms-btn btn-primary" ${empty subSuppliers ? '' : 'disabled'}>确定</button>
        <button type="button" class="btn ms-btn ms-btn-gary" data-dismiss="modal">取消</button>
      </div>

    </form>

  </div>
</div>

<script type="text/javascript">
  $(document).ready(function () {

    $('select[name="parents"]').select2({
      theme: "classic",
      placeholder: '请选择',
      minimumResultsForSearch: Infinity,
      allowClear: true,
    });

  })
</script>